package net.beyondts.example.mplug.extension;

import net.beyondts.crypto.Crypto;
import net.beyondts.crypto.symmetric.AES;
import net.beyondts.crypto.symmetric.SymmetricCrypto;
import net.beyondts.mplug.annotation.Extension;
import net.beyondts.mplug.utils.BeanFactory;
import org.springframework.stereotype.Service;

import java.lang.reflect.InvocationTargetException;

/**
 * Project: mplug-project<br/>
 * Description: <br/>
 * Created at: 2019-1-12<br/>
 * Owned by beyondts.
 *
 * @author blazecrystal
 * @version 1.0.0
 */
@Service
public class SomeService/* extends Self*/ {

    @Extension(id = "void net.beyondts.example.mplug.extension.SomeService.print()")
    public void print() {
        System.out.println("---- this is default ---");
    }

    @Extension(id = "void net.beyondts.example.mplug.extension.SomeService.print(int)")
    public void print(int x) {
        System.out.println("---- this is default with 1 input : " + x + " ------");
    }

    public void print(String a, int b) {
        System.out.println("--- this is default with 2 input : " + a + ", " + b + " ---");
        try {
            AES aes = AES.newInstance(Crypto.MODE_CBC, Crypto.PADDING_PKCS5, "12345678abcdefgh!@#$%^&*", SymmetricCrypto.KEY_LENGTH_128);
            String x = aes.encrypt("abc", true);
            System.out.println(x);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void testPrint(String x) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
//        System.out.println(invokeSelf("test", x));
        System.out.println(BeanFactory.getBean(SomeService.class).test(x));
//        System.out.println(this.test(x));
    }

//    @Extension(id = "String net.beyondts.example.mplug.extension.SomeService.test(String)")
    public String test(String x) {
        return x + "default";
    }
}
